import type { Ref } from 'vue'
import type { Student } from './useClassManagement'
import message from '@/components/common/message'
import { removeStudentFromClass } from '@/request/class'

export function useStudentManagement(classId: Ref<string>, students: Ref<Student[]>) {
  // 移除学生
  async function handleRemoveStudent(student: Student) {
    if (!classId.value)
      return

    try {
      await removeStudentFromClass({
        cid: classId.value,
        student: { sid: student.sid },
      })

      students.value = students.value.filter(s => s.sid !== student.sid)
      message.success('学生移除成功')
    }
    catch (error) {
      console.error('移除学生失败:', error)
      message.error('移除学生失败')
    }
  }

  return {
    handleRemoveStudent,
  }
}
